<?php
load_ctl("admin_Common");
class Admin_ClassController extends Admin_CommonController {
	function init(){
		parent::init();
		load_model('Class');
		$this->class = new APclass();
		load_model('Topic');
		$this->topic = new topic();
	}
	public function indexAction(){
		$this->view->title = "文章分类信息";
		$this->view->class_list = $this->class->get_class_list();
		
		$this->view->mainphp = 'views/scripts/admin/index/class.phtml';
		echo $this->view->render("index.phtml");
	}
	public function addclassAction(){
		$this->view->action = 'add';
		$this->view->class_list = $this->class->get_class_list();
		$this->view->topic_list = $this->topic->get_topic_list();
		$this->view->mainphp = 'views/scripts/admin/index/addclass.phtml';
		echo $this->view->render("index.phtml");
	}
	public function editclassAction(){
		$this->view->class_list = $this->class->get_class_list();
		$this->view->topic_list = $this->topic->get_topic_list();
		$this->view->action = 'edit';
		$id = $this->_request->get('id');
		$this->view->class_info = $this->class->get_class_info($id);
		$this->view->mainphp = 'views/scripts/admin/index/addclass.phtml';
		echo $this->view->render("index.phtml");
	}
	function submitclassAction(){
		if($this->_request->isPost()){
			$filter = new Zend_Filter_StripTags();
			$data = array(
				'class_fid'=>$this->_request->getPost('fid'),
				'class_name'=>$filter->filter($this->_request->getPost('class_name')),
				'class_level'=>'1',
				'class_top'=>$this->_request->getPost('top_id'),
				'class_if_show'=>$this->_request->getPost('class_if_show'),
			);
			
			$action = $this->_request->getPost('action');
			if ($action == 'edit') {	//修改
				$id = intval($filter->filter($this->_request->getPost('id')));
				$this->class->update_class($id,$data);
				php_alert('修改类别成功');
			}else if($action == 'add') {//新增
				$this->class->add_class($data);
				php_alert('添加类别成功');
			}
			$this->_redirect("admin/class");
		}else if(isset($_GET["action"]) && $_GET["action"] == 'del'){
			$filter = new Zend_Filter_StripTags();
			$id = intval($filter->filter($this->_request->get('id')));
			$this->class->del_class($id);
			php_alert('删除类别成功');
			$this->_redirect("admin/class");
		}
	}
}
?>